﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.03.22
 * 描 述：支付数据查询表
 */

 var companyId = '';
 var kjnd = '';
 var userdefault = {};
var params = {};


var selectedRow;
var refreshGirdData;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            userdefault = learun.clientdata.get(['usersetting']);
            page.initGrid();
            page.bind();
        },
        bind: function () {
            // 搜索框初始化
            $('#keyword').on("keypress", function (e) {
                if (event.keyCode == "13") {
                    var $this = $(this);
                    var keyword = $this.val();
                    page.search({keyword: keyword});
                }
            });
            $('#multiple_condition_query').lrMultipleQuery(function (queryJson) {
                page.search(queryJson);
            }, 440, 980);
            $('#pzrqMonth').lrselect({
                type: 'default',
                // 展开最大高度
                maxHeight: 300,
                placeholder: '月份',
                data: [
                    {'id': '01', 'text': '01'},
                    {'id': '02', 'text': '02'},
                    {'id': '03', 'text': '03'},
                    {'id': '04', 'text': '04'},
                    {'id': '05', 'text': '05'},
                    {'id': '06', 'text': '06'},
                    {'id': '07', 'text': '07'},
                    {'id': '08', 'text': '08'},
                    {'id': '09', 'text': '09'},
                    {'id': '10', 'text': '10'},
                    {'id': '11', 'text': '11'},
                    {'id': '12', 'text': '12'}
                ],
                select: function (item) {
                    if (!item || item.id == '-1') {
                        var beginDate = kjnd + "-01-01";
                        var day = new Date(kjnd, 12, 0);
                        var endDate = kjnd + "-" + 12 + "-" + day.getDate();
                        $("#pzrqStart").val('');
                        $("#pzrqEnd").val(endDate);
                    } else {
                        var kjqj = item.id;
                        var beginDate = kjnd + "-" + kjqj + "-01";
                        var day = new Date(kjnd, kjqj, 0);
                        var endDate = kjnd + "-" + kjqj + "-" + day.getDate();
                        $("#pzrqStart").val(beginDate);
                        $("#pzrqEnd").val(endDate);
                    }
                }
            });
            // 公司选择
            $('#company_select').lrselect({
                type: 'tree',
                placeholder: '全系统',
                height: 300,
                maxHeight: 300,
                // 是否允许搜索
                //allowSearch: true,
                select: function (item) {
                    if (item && item.value != '-1') {
                        companyId = item.value;
                    } else {
                        companyId = "";
                    }
                }
            });
            $('#company_select').lrselectRefresh({
                placeholder: '全系统',
                // 访问数据接口地址
                url: config.base_server() + 'companys/tree?access_token=' + config.getToken().access_token,
                // 访问数据接口参数
                param: {parentId: '0'}
            });

            // 会计年度选择
            $('#kjnd_select').lrDataItemSelect({
                code: 'YEAR', maxHeight: 100,
                placeholder: "==请选择年份==",
                select: function (item) {
                    if (!item || item.value == '-1') {
                        kjnd = '';
                    } else {
                        kjnd = item.value;

                        var beginDate = kjnd + "-01-01";
                        var day = new Date(kjnd, 12, 0);
                        var endDate = kjnd + "-12-" + day.getDate();
                        //$("#pzrqStart").val(beginDate);
                        $("#pzrqEnd").val(endDate);
                    }
                }
            });

            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#keyword').val();
                page.search({keyword: keyword});
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });

           //导出Excel
            $("#lr_export_excel").on('click', function () {
                if (params.companyId == undefined) {
                    learun.alert.warning('请先查询要导出的数据！');
                    return;
                }
                params.access_token = config.getToken().access_token;

                learun.download({
                    url: config.base_server() + 'payvoucherbills/exportExcel',
                    param: params
                });
            });
        },



        initGrid: function () {
            $('#gridtable').jfGrid({
                url: config.base_server() + 'payvoucherbills/list?access_token=' + config.getToken().access_token,
                headData: [

                     {label: '指标id', name: 'bgtId', width: 80, align: 'left'},
                     {label: '科室编码', name: 'bgtMofDepCode', width: 90, align: 'left'},
                     {label: '科室名称', name: 'bgtMofDepName', width: 90, align: 'left'},
                     {label: '单位编号', name: 'agencyCode', width: 90, align: 'left'},
                     {label: '单位名称', name: 'agencyName', width: 180, align: 'left'},
                     {label: '代理行号', name: 'agentBankCode', width: 60, align: 'left'},
                     {label: '代理行名称', name: 'agentBankName', width: 180, align: 'left'},
                     {label: '申请号', name: 'applyNo', width: 210, align: 'left'},
                     {label: '凭证号', name: 'payCertNo', width: 210, align: 'left'},
                     {label: '业务类型编码', name: 'businessTypeCode', width: 60, align: 'left'},
                     {label: '业务类型名称', name: 'businessTypeName', width: 90, align: 'left'},
                     {label: '预算级次', name: 'budgetLevelName', width: 60, align: 'left'},
                     {label: '功能分类编码', name: 'expFuncCode', width: 90, align: 'left'},
                     {label: '功能分类名称', name: 'expFuncName', width: 120, align: 'left'},
                     {label: '项目类型编码', name: 'proCateCode', width: 60, align: 'left'},
                     {label: '项目类型名称', name: 'proCateName', width: 90, align: 'left'},
                     {label: '一级项目编码', name: 'proCode', width: 180, align: 'left'},
                     {label: '一级项目名称', name: 'proName', width: 180, align: 'left'},
                     {label: '预算项目编码', name: 'bgtProCode', width: 180, align: 'left'},
                     {label: '预算项目名称', name: 'bgtProName', width: 180, align: 'left'},
//                     {label: '项目22', name: 'parentProCode', width: 180, align: 'left'},
//                     {label: '项目333', name: 'parentProName', width: 180, align: 'left'},
                     {label: '人员类项目目录编码', name: 'personCatalogueCode', width: 60, align: 'left'},
                     {label: '人员类项目目录名称', name: 'personCatalogueName', width: 150, align: 'left'},
                     {label: '结算方式名称', name: 'setModeCode', width: 60, align: 'left'},
                     {label: '结算方式名称', name: 'setModeName', width: 120, align: 'left'},
                     {label: '支付方式', name: 'payTypeName', width: 120, align: 'left'},
                     {label: '支付方向编码', name: 'proPayDicCode', width: 60, align: 'left'},
                     {label: '支付方向名称', name: 'proPayDicName', width: 100, align: 'left'},
                     {label: '政府经济分类编码', name: 'govBgtEcoCode', width: 90, align: 'left'},
                     {label: '政府经济分类名称', name: 'govBgtEcoName', width: 180, align: 'left'},
                     {label: '部门经济分类编码', name: 'depBgtEcoCode', width: 90, align: 'left'},
                     {label: '部门经济分类名称', name: 'depBgtEcoName', width: 180, align: 'left'},
                     {label: '项目分类编码', name: 'proCatCode', width: 80, align: 'left'},
                     {label: '项目分类名称', name: 'proCatName', width: 180, align: 'left'},
                     {label: '指标来源预算处编码', name: 'sourceTypeYscCode', width: 90, align: 'left'},
                     {label: '指标来源预算处名称', name: 'sourceTypeYscName', width: 180, align: 'left'},
                     {label: '指标来源', name: 'sourceName', width: 100, align: 'left'},
                     {label: '指标文批', name: 'corBgtDocNo', width: 180, align: 'left'},
                     {label: '支付金额', name: 'payAmt', width: 180, align: 'right'},
                     {label: '资金用途', name: 'useFund', width: 100, align: 'left'},
                     {
                        label: "制单日期", name: "vouDate", width: 140, align: "center",
                        formatter: function (value) {
                            return learun.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
                        }
                     },
                     {
                        label: "支付日期", name: "actPayDate", width: 140, align: "center",
                        formatter: function (value) {
                            return learun.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
                        }
                     },
                     {label: '付款方账号', name: 'payerAccNo', width: 180, align: 'left'},
                     {label: '付款方名称', name: 'payerName', width: 180, align: 'left'},
                     {label: '收款方账号', name: 'receiverAccNo', width: 180, align: 'left'},
                     {label: '收款方名称', name: 'receiverName', width: 180, align: 'left'},
                     {label: 'id', name: 'id', width: 80, align: 'left', hidden: true},
                ],
                isPage: true,
                reloadSelected: true,
                mainId: 'id'
            });

            page.search();
        },
        search: function (param) {
            param = param || {};

            var pzrqStart = $("#pzrqStart").val();
            var pzrqEnd = $("#pzrqEnd").val();
            param.companyId = companyId;
            param.kjnd = kjnd;
            param.pzrqStart = pzrqStart;
            param.pzrqEnd = pzrqEnd;

            var formData = $('.lr-query-formcontent').lrGetFormData();

            params = param;

            $('#gridtable').jfGridSet('reload', param);
        }
    };

    refreshGirdData = function () {
        page.search();
    };

    page.init();
}


